<template>
  <commonBox title="部门资产分布" width="1100px" height="492px">
    <div class="chart-container">
      <echarts-component :option="option" width="1000px"></echarts-component>
    </div>
  </commonBox>
</template>

<script setup>
import { ref, onMounted, watch } from "vue";
import echartsComponent from "@/components/echartsComponent.vue";
import commonBox from "../commonBox.vue";
const props = defineProps({
  departmentAssets: {
    type: Array,
    default: () => [],
  },
});
const xData = ref([]);
const yData = ref([]);
xData.value = props.departmentAssets.map((item) => item.name);
yData.value = props.departmentAssets.map((item) => item.value);
const option = ref({});
onMounted(() => {
  option.value = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    grid: {
      left: "3%",
      right: "4%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: xData.value,
        axisTick: {
          alignWithLabel: true,
        },
        axisLabel: {
          color: "#000000",
          fontSize: 10, //如果全部显示不开,可以选择字体大小
          interval: 1, //控制是否全部显示
        },
      },
    ],
    yAxis: [
      {
        type: "value",
      },
    ],
    series: [
      {
        name: "资产数量",
        type: "bar",
        barWidth: "60%",
        data: yData.value,
      },
    ],
  };
});
</script>

<style scoped lang="less">
.department-container {
  width: 684px;
  height: 492px;
  padding: 24px;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.001), rgba(0, 0, 0, 0.001)),
    #ffffff;
  box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
  .department-header {
    width: 100%;
    height: 38px;
    .header-title {
      font-size: 24px;
      font-weight: 600;
      color: #333;
      float: left;
    }
  }
}
</style>
